﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class CommonFunction {

    //通用场景切换
    public static void SceneSwitch(GameScene fromScene, GameScene toScene) {
        GlobalData.sceneLoadingAsync = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync((int)toScene, UnityEngine.SceneManagement.LoadSceneMode.Additive);
        //UnityEngine.SceneManagement.SceneManager.SetActiveScene(UnityEngine.SceneManagement.SceneManager.GetSceneByBuildIndex((int)toScene));
        UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync((int)fromScene);
        GlobalData.nowGameScene = toScene;
    }

    public static void SceneLoad(GameScene scene) {
        GlobalData.sceneLoadingAsync = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync((int)scene, UnityEngine.SceneManagement.LoadSceneMode.Additive);
        //UnityEngine.SceneManagement.SceneManager.SetActiveScene(UnityEngine.SceneManagement.SceneManager.GetSceneByBuildIndex((int)scene));
    }

    //平滑移动
    public static void SmoothMove(Transform mover, Vector3 startPos, Vector3 endPos, float nowTime, float allTime, bool check = true) {
        if (check == true) {
            mover.transform.position = Mathf.Clamp01(nowTime / allTime) * (endPos - startPos) + startPos;
        }
        else {
            mover.transform.position = (nowTime / allTime) * (endPos - startPos) + startPos;
        }
    }

    public static void SendErrorMsg(string str, _TriggerEventManager _TriggerEventManager) {
        _TriggerEventManager.TriggerEvent("ErrorMsg", str);
    }

    //通用退出游戏
    public static void Quit() {
#if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;
#endif
        Application.Quit();
    }

}
